<template>
	<view class="content">
		<text class="title">
			{{work.jobName}}
		</text>
		<view class="price">
			<text style="font-size: 50upx;font-weight: 600;">{{work.price}}</text>
			<text style="font-size: 30upx;margin-left: 20upx;">元 {{work.type}}</text>
		</view>
		<view class="people">
			<image src="../../static/images/lianxi.png" mode=""></image>
			<text class="tips">招聘人数</text>
			<text class="maxPeople">所招{{work.maxPeople}}人</text>
		</view>
		<view class="address">
			<uni-icon type="map" size="16" color="#000000"></uni-icon><text @tap="openURL(work.address)" style="margin-left: 12upx;">{{work.address}}</text>
			<uni-icon type="arrowright" size="16" color="#000000"></uni-icon>
		</view>
		<text class="title">兼职详情</text>
		<text class="time">发布日期:{{formatTime(work.createTime)}}</text>
		<view class="desc">
			<text>{{work.jobDesc}}</text>
		</view>
		<view @tap="contact" class="contact">立即联系</view>
	</view>
</template>

<script>
	import utils from "../../static/js/utils.js";
	import uniIcon from "@/components/uni-icon/uni-icon.vue"
	export default {
		data() {
			return {
				work: {}
			}
		},
		components: {
			uniIcon
		},
		methods: {
			openURL(address) {
				let url = "";
				// #ifdef APP-PLUS
				if (plus.os.name == "Android") {
					var hasBaiduMap = plus.runtime.isApplicationExist({
						pname: 'com.baidu.BaiduMap',
						action: 'baidumap://'
					});
					var hasAmap = plus.runtime.isApplicationExist({
						pname: 'com.autonavi.minimap',
						action: 'androidamap://'
					});
					var urlBaiduMap = "baidumap://map/geocoder?src=andr.baidu.openAPIdemo&address=" + address;
					var urlAmap =
						"androidamap://poi?sourceApplication=softname&keywords="+address;
					if (hasAmap && hasBaiduMap) {
						plus.nativeUI.actionSheet({
							title: "选择地图应用",
							cancel: "取消",
							buttons: [{
								title: "百度地图"
							}, {
								title: "高德地图"
							}]
						}, function(e) {
							switch (e.index) {
								case 1:
									plus.runtime.openURL(urlBaiduMap);
									break;
								case 2:
									plus.runtime.openURL(urlAmap);
									break;
							}
						})
					} else if (hasAmap) {
						plus.runtime.openURL(encodeURI(urlAmap));
					} else if (hasBaiduMap) {
						plus.runtime.openURL(encodeURI(urlBaiduMap));
					} else { 
						plus.runtime.openURL("http://api.map.baidu.com/geocoder?address=" + address + "&output=html&src=kevinproject.cn");
					}
				} else {
					plus.nativeUI.actionSheet({
						title: "选择地图应用",
						cancel: "取消",
						buttons: [{title:"Apple地图"},{
							title: "百度地图"
						}, {
							title: "高德地图"
						}]
					}, function(e) {
						switch (e.index) {
							case 1:
								 url = "http://maps.apple.com/?q="+address;  
								break;
							case 2:
								url = "baidumap://map/geocoder?src=andr.baidu.openAPIdemo&address=" + address;
								break;
							case 3:
								url =
									"iosamap://poi?sourceApplication=campus&name="+address;
								break;
							default:
								break;
						}
						if (url != "") {
							url = encodeURI(url);
							plus.runtime.openURL(url, function(e) {
								plus.nativeUI.alert("本机未安装指定的地图应用");
							});
						}
					})
				}
				// #endif
				// #ifdef MP-WEIXIN
				url = "http://api.map.baidu.com/geocoder?address=" + address + "&output=html&src=kevinproject.cn"
				uni.setClipboardData({
					data: url
				});
				uni.showModal({
					content: '本网址无法直接在小程序内打开。已自动复制网址，请在手机浏览器里粘贴该网址',
					showCancel: false
				});
				// #endif
			},
			formatTime(timestamp) {
				var da = new Date(timestamp);
				return (da.getMonth() + 1) + "-" + da.getDate();
			},
			contact() {
				uni.makePhoneCall({
					phoneNumber: this.work.message
				});
			},

		},
		onLoad(option) {
			let workId = option.workId;
			let that = this;
			utils.post("job/getjob", {
				jobId: workId
			}, function(data) {
				that.work = data;
			}, function(msg) {
				uni.navigateBack({
					delta: 1
				})
			})
		}
	}
</script>

<style>
	.content {
		width: 100%;
		display: flex;
		flex-direction: column;
		margin: 0px auto;
		align-items: center;
	}

	.title {
		width: 92%;
		font-size: 46upx;
		font-weight: 600;
		margin-top: 20upx;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
	}

	.price {
		height: 80upx;
		display: flex;
		flex-direction: row;
		align-items: flex-end;
		color: #FF6601;
		width: 92%;
	}

	.people {
		width: 92%;
		height: 100upx;
		display: flex;
		flex-direction: row;
		align-items: center;
		box-shadow: inset 0px -1px 1px -1px #dcdcdc;

	}

	.people image {
		width: 30upx;
		height: 30upx;
	}

	.tips {
		font-size: 26upx;
		margin-left: 10upx;
	}

	.maxPeople {
		font-size: 26upx;
		color: #999999;
		margin-left: 15upx;
	}

	.time {
		width: 92%;
		font-size: 24upx;
		color: #999999;
		margin-top: 15upx;
	}

	.desc {
		width: 92%;
		font-size: 28upx;
		color: #999999;
		margin-top: 40upx;
		margin-right: 10upx;
	}

	.contact {
		width: 100%;
		height: 100upx;
		background-color: #3FCEC6;
		color: white;
		position: fixed;
		line-height: 100upx;
		text-align: center;
		bottom: 0;
		font-size: 30upx;
	}

	.address {
		width: 92%;
		display: flex;
		flex-direction: row;
		height: 80upx;
		font-size: 24upx;
		box-shadow: inset 0px -1px 1px -1px #dcdcdc;
		align-items: center;
	}
</style>
